<?php
declare (strict_types=1);

namespace app\admin\model\base;

use aliyun\AliyunOss;
use app\BaseModel;

/**
 * 管理员和角色关系表
 */
class AdminRoleAccess extends BaseModel
{

    /**
     * 获取角色已分配用户列表
     * @param array $where
     * @param int $page
     * @param int $limit
     * @param string $orderby
     * @return array
     */
    public static function roleAssignedList(array $where, int $page, int $limit, string $orderby = ''): array
    {
        $data = self::alias('a')
            ->field('a.admin_id,a.role_id,b.name,b.phone,b.avatar,b.desc,b.enable,b.create_time')
            ->where($where)
            ->leftJoin((new Admin())->getTable() . ' b', 'a.admin_id = b.id')
            ->order($orderby)
            ->paginate(['list_rows' => $limit, 'page' => $page], false)
            ->toArray();
        $AliyunOss = new AliyunOss();
        //遍历数组
        foreach ($data['data'] as $k => &$v) {
            $v['avatar'] = $v['avatar'] ?: config('ws_config.avatar');
            $v['avatar'] = $AliyunOss->getObjectUrl($v['avatar']);
        }
        return $data;
    }


}




